import Vue from 'vue'
import Router from 'vue-router'
import Home from '../pages/home/home'
import jiuHome from '../pages/jiuHome/jiuHome'
import { Topic1,Topic2,Topic3,Topic4,Topic5 } from '../pages/topic'
import SuccessNull from '../pages/success/success-null'
import SuccessInfo from '../pages/success/success-info'
import Iview from '../components/iviews/iview'
import ListTest from '../pages/list_test'

Vue.use(Router)
const router = new Router({
  routes: [
    // {
    //   path: '*',
    //   component: Home
    // },
    // {
    //   path: '/',
    //   component: Home
    // },
    {
      path: '/jiuHome',
      component: jiuHome
    },
    {
      path: '/Topic_1',
      component: Topic1
    },
    {
      path: '/Topic_2',
      component: Topic2
    },
    {
      path: '/Topic_3',
      component: Topic3
    },
    {
      path: '/Topic_4',
      component: Topic4
    },
    {
      path: '/Topic_5',
      component: Topic5
    },
    {
      path: '/success_info',
      component: SuccessInfo
    },
    {
      path: '/success_null',
      component: SuccessNull
    },
    {
      path: '/iviews',
      component: Iview
    },
    {
      path: '/listtest',
      component: ListTest
    }
  ]

})

router.beforeEach((to, from, next) => {
  const requestData = sessionStorage.getItem('requestData')
  if (to.fullPath !== '/') {
    // 对路由进行验证
    if (!requestData) { //
      // 未登录,跳转到登陆页面，并且带上 将要去的地址，方便登陆后跳转。      location.href = './'
      next({path: '/', replace: true})
    } else {
      next()
    }
  } else {
    next()
  }
})

export default router
